<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Create account form template
 *
 * @var $this \Magento\Customer\Block\Form\Register
 */
?>
<?php echo $this->getChildHtml('form_fields_before')?>
<?php /* Extensions placeholder */ ?>
<?php echo $this->getChildHtml('customer.form.register.extra')?>
<form class="form create account" action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
    <fieldset class="fieldset create info">
        <legend class="legend"><span><?php echo __('Personal Information') ?></span></legend><br>
        <input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>">
        <input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>">
        <?php echo $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
        <div class="field required">
            <label for="email_address" class="label"><span><?php echo __('Email Address') ?></span></label>
            <div class="control">
                <input type="email" name="email" id="email_address" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo __('Email Address') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
            </div>
        </div>
        <?php if ($this->isNewsletterEnabled()): ?>
            <div class="field choice newsletter">
                <input type="checkbox" name="is_subscribed" title="<?php echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
                <label for="is_subscribed" class="label"><span><?php echo __('Sign Up for Newsletter') ?></span></label>
            </div>
            <?php /* Extensions placeholder */ ?>
            <?php echo $this->getChildHtml('customer.form.register.newsletter')?>
        <?php endif ?>

        <?php $_dob = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
        <?php if ($_dob->isEnabled()): ?>
            <?php echo $_dob->setDate($this->getFormData()->getDob())->toHtml() ?>
        <?php endif ?>

        <?php $_taxvat = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?>
        <?php if ($_taxvat->isEnabled()): ?>
            <?php echo $_taxvat->setTaxvat($this->getFormData()->getTaxvat())->toHtml() ?>
        <?php endif ?>

        <?php $_gender = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?>
        <?php if ($_gender->isEnabled()): ?>
            <?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?>
        <?php endif ?>
    </fieldset>
    <?php if($this->getShowAddressFields()): ?>
        <fieldset class="fieldset address">
            <legend class="legend"><span><?php echo __('Address Information') ?></span></legend><br>
            <input type="hidden" name="create_address" value="1" />
            <div class="field company">
                <label for="company" class="label"><span><?php echo __('Company') ?></span></label>
                <div class="control">
                    <input type="text" name="company" id="company" value="<?php echo $this->escapeHtml($this->getFormData()->getCompany()) ?>" title="<?php echo __('Company') ?>" class="input-text <?php echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('company') ?>">
                </div>
            </div>
            <div class="field telephone">
                <label for="telephone" class="label"><span><?php echo __('Phone Number') ?></span></label>
                <div class="control">
                    <input type="text" name="telephone" id="telephone" value="<?php echo $this->escapeHtml($this->getFormData()->getTelephone()) ?>" title="<?php echo __('Phone Number') ?>" class="input-text <?php echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('telephone') ?>">
                </div>
            </div>

            <?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?>

            <div class="field street required">
                <label for="street_1" class="label"><span><?php echo __('Street Address') ?></span></label>
                <div class="control">
                    <input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet(0)) ?>" title="<?php echo __('Street Address') ?>" id="street_1" class="input-text <?php echo $_streetValidationClass ?>">
                    <div class="nested">
                        <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
                        <?php for ($_i = 2, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i <= $_n; $_i++): ?>
                            <div class="field additional no-label">
                                <div class="control">
                                    <input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet($_i - 1)) ?>" title="<?php echo __('Street Address %1', $_i) ?>" id="street_<?php echo $_i ?>" class="input-text <?php echo $_streetValidationClass ?>">
                                </div>
                            </div>
                        <?php endfor; ?>
                    </div>
                </div>
            </div>

            <div class="field required">
                <label for="city" class="label"><span><?php echo __('City') ?></span></label>
                <div class="control">
                    <input type="text" name="city" value="<?php echo $this->escapeHtml($this->getFormData()->getCity()) ?>" title="<?php echo __('City') ?>" class="input-text <?php echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city') ?>" id="city">
                </div>
            </div>

            <div class="field region required">
                <label for="region_id" class="label"><span><?php echo __('State/Province') ?></span></label>
                <div class="control">
                    <select id="region_id" name="region_id" title="<?php echo __('State/Province') ?>" class="validate-select" style="display:none;">
                        <option value=""><?php echo __('Please select region, state or province') ?></option>
                    </select>
                    <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo __('State/Province') ?>" class="input-text <?php echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region') ?>" style="display:none;">
                </div>
            </div>

            <div class="field zip required">
                <label for="zip" class="label"><span><?php echo __('Zip/Postal Code') ?></span></label>
                <div class="control">
                    <input type="text" name="postcode" value="<?php echo $this->escapeHtml($this->getFormData()->getPostcode()) ?>" title="<?php echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode') ?>">
                </div>
            </div>

            <div class="field country required">
                <label for="country" class="label"><span><?php echo __('Country') ?></span></label>
                <div class="control">
                    <?php echo $this->getCountryHtmlSelect() ?>
                </div>
            </div>
            <?php $addressAttributes = $this->getChildBlock('customer_form_address_user_attributes');?>
            <?php if ($addressAttributes): ?>
                <?php $addressAttributes->setEntityType('customer_address'); ?>
                <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
                <?php $this->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
                <?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
            <?php endif;?>
            <input type="hidden" name="default_billing" value="1">
            <input type="hidden" name="default_shipping" value="1">
        </fieldset>

    <?php endif; ?>
    <fieldset class="fieldset create account" data-hasrequired="<?php echo __('* Required Fields') ?>">
        <legend class="legend"><span><?php echo __('Login Information') ?></span></legend><br>

        <div class="field password required">
            <label for="password" class="label"><span><?php echo __('Password') ?></span></label>
            <div class="control">
                <input type="password" name="password" id="password" title="<?php echo __('Password') ?>" class="input-text" data-validate="{required:true, 'validate-password':true}">
            </div>
        </div>
        <div class="field confirmation required">
            <label for="confirmation" class="label"><span><?php echo __('Confirm Password') ?></span></label>
            <div class="control">
                <input type="password" name="confirmation" title="<?php echo __('Confirm Password') ?>" id="confirmation" class="input-text" data-validate="{required:true, equalTo:'#password'}">
            </div>
        </div>
        <?php echo $this->getChildHtml('form_additional_info'); ?>
    </fieldset>
    <div class="actions-toolbar">
        <div class="primary">
            <button type="submit" class="action submit primary" title="<?php echo __('Create account') ?>"><span><?php echo __('Create account') ?></span></button>
        </div>
        <div class="secondary">
            <a class="action back" href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>"><span><?php echo __('Back') ?></span></a>
        </div>
    </div>
</form>
<script type="text/javascript">
require(['jquery', "mage/mage"], function(jQuery){

    (function($) {
        var dataForm = $('#form-validate');
        var ignore = <?php echo $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null'; ?>;
        dataForm.mage('validation', {
        <?php if ($_dob->isEnabled()): ?>
            errorPlacement: function(error, element) {
                if (element.prop('id').search('full') !== -1) {
                    var dobElement = $(element).parents('.customer-dob'),
                        errorClass = error.prop('class');
                    error.insertAfter(element.parent());
                    dobElement.find('.validate-custom').addClass(errorClass)
                        .after('<div class="' + errorClass + '"></div>');
                }
                else {
                    error.insertAfter(element);
                }
            },
            ignore: ':hidden:not(' + ignore + ')'
        <?php else: ?>
            ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
        <?php endif ?>
        }).find('input:text').attr('autocomplete', 'off');
        <?php if ($this->getShowAddressFields()): ?>
        $('#country').mage('regionUpdater', {
            optionalRegionAllowed: <?php echo ($this->getConfig('general/region/display_all')? 'true' : 'false'); ?>,
            regionListId: '#region_id',
            regionInputId: '#region',
            postcodeId: '#zip',
            form: dataForm,
            regionJson: <?php echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
            defaultRegion: "<?php echo $this->getFormData()->getRegionId() ?>",
            countriesWithOptionalZip: <?php echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
        });
        <?php endif; ?>
    })(jQuery);

});
</script>
